<!doctype html>
<html>
<head>
<title>Registration Form</title>
<meta name="robots" content="noindex, nofollow">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


<script>
function validateForm() {
	$(document).ready(function() {
	$("#register").click(function() {
		var ok = true;
		var name = $("#name").val();
		var lastname = $("#lastname").val();
		var username = $("#username").val();
		var password = $("#password").val();
		var cpassword = $("#cpassword").val();
		var email = $("#email").val();
		var patternForDigits = /^\d+$/;
		var patternForSpecialSymbols = /[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]/;
		var x = document.forms["registerform"]["email"].value;
		var atpos = x.indexOf("@");
		var dotpos = x.lastIndexOf(".");
			if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) {
					alert("Not a valid e-mail address");  ok = false;
				} else if (name == "" || password == '' || cpassword == '' || lastname == '' || username == '' || email =='') {
					alert("Please fill all fields!"); ok = false;
				} else if ((password.length) < 6) {
					alert("Password should at least 6 character!");  ok = false;
				} else if (!(password).match(cpassword)) {
					alert("The passwords don't match.");  ok = false;
				} else if ((username.length) < 4){
					alert("Enter valid Username.");  ok = false;
				} else if ((patternForDigits.test(name)) == true){
					alert("The Name can not contain numbers");  
				} else if ((patternForDigits.test(lastname)) == true){
					alert("Your Last Name can not contain numbers"); 
				} else if ((patternForDigits.test(username)) == true){
					alert("Your Username can not contain numbers");  
				}  else if ((patternForSpecialSymbols.test(name)) == true){
					alert("Your Name can not contain special symbols");  
				}  else if ((patternForSpecialSymbols.test(lastname)) == true){
					alert("Your Last Name can not contain special symbols");  
				}  else if ((patternForSpecialSymbols.test(username)) == true){
					alert("Your Username can not contain special symbols");	 		
				}	
			if (ok){
				window.location.href = "congrat.html";
			}
		})
		
		});
}

validateForm();
</script>
</head>
<body>
<fieldset>
<div class="container">
	<div class="main">
		<form class="form" onSubmit="return false"id="registerform" method="get" action="congrat.html">
			<h2>Registration Form</h2>
							<label>Name: </label>
								<center>
									<input type='text' name="dname" id="name" maxlength="10" placeholder="Name"/>
								</center>
								
							<label> Last Name: </label>
								<center>
									<input type='text' name="dlastname" id="lastname" maxlength="10" placeholder="Last Name"/>
								</center>
								
							<label> Username: </label>
								<center>
									<input type='text' name="dusername" id="username" maxlength="10" placeholder="Username"/>
								</center>
								
							<label> E-mail: </label>
								<center>
									<input type='text' name="emailcheck" id="email" maxlength="15" placeholder="E-mail"/>
								</center>										
								
							<label for='password' >Password: </label>
								<center>
									<input type="password" name="password" id="password" maxlength="12" placeholder="Password"/>
								</center>
								
							<label>Confirm Password :</label>
								<center>
									<input type="password" name="cpassword" id="cpassword" maxlength="12" placeholder="Confirm Password"/>
								</center>
								
					<input type="Submit" id="register" value="Register">
		</form>
	</div>
</div>
</fieldset>
</body>
</html>